import os
from jinja2 import Environment, FileSystemLoader


class HtmlReportGenerator:
    def __init__(self, template_dir='templates'):
        self.env = Environment(loader=FileSystemLoader(template_dir))

    def generate_report(self, aggregated_by_file, aggregated_by_line, assembly_info, output_file='output/report.html'):
        template = self.env.get_template('report_template.html')
        html_content = template.render(aggregated_by_file=aggregated_by_file, aggregated_results=aggregated_by_line,
                                       assembly_info=assembly_info)
        output_dir = os.path.dirname(output_file)
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)
        with open(output_file, 'w', encoding='utf-8') as f:
            f.write(html_content)
